package com.xysd.express.app;

import android.app.Application;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;

import com.xysd.express.base.BaseActivity;

import org.xutils.x;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by donghui on 2017/6/16.
 */

public class App extends Application {
    public String paySuccessUrl="";
    public String wexinAppId="";
    public static String versionCode;

    static App app;
    private static List<BaseActivity> activityList; //acticity管理
    public static App getInstance(){
        return app;
    }


    @Override
    public void onCreate() {
        super.onCreate();
        app=this;
        activityList = new ArrayList<>();
        x.Ext.init(this);
        x.Ext.setDebug(true);
        try {
            versionCode=getVersionInfo("code");
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
    }


    /**
     * 获取当前程序的版本号和版本名
     *
     * @param type "code"版本号，“name”版本名
     * @return
     * @throws PackageManager.NameNotFoundException
     */
    public String getVersionInfo(String type) throws PackageManager.NameNotFoundException {
        //获取packagemanager的实例
        PackageManager packageManager = getPackageManager();
        //getPackageName()是你当前类的包名，0代表是获取版本信息
        PackageInfo packInfo;
        packInfo = packageManager.getPackageInfo(getPackageName(), 0);
        if ("code".equals(type)) {//获取版本号
            return packInfo.versionCode + "";
        } else if ("name".equals(type)) {//获取版本名
            return packInfo.versionName;
        }
        return null;
    }

}
